package com.qingzhuge.netty.common.message;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

/**
 * @author : zero.xiao
 * @description :
 * @date :2018/9/28 0028 下午 14:48
 * @since : 1.0.0
 * @modified :
 */
public class MessageDecoder extends ByteToMessageDecoder {

	@Override
	protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
		  int len = in.readableBytes();
		  byte[] bytes = new byte[len];
		  in.readBytes(bytes);
		  HeartBeatMessage  msg = new HeartBeatMessage();
		  msg.setHeartbeat(new String(bytes));
		  out.add(msg);
	}

}
